import type { ConsultType } from '@/enum'
import type { PartialConsult, ConsultIllness } from '@/types/consult'
import { defineStore } from 'pinia'
import { ref } from 'vue'

export const useConsultStore = defineStore(
  'cp-consult',
  () => {
    // 1. 问诊记录对象
    const consult = ref<PartialConsult>({})
    // 2. 设置问诊类型
    const setType = (type: ConsultType) => (consult.value.type = type)
    // 3. 设置急速问诊类型
    const setIllnessType = (type: 0 | 1) => (consult.value.illnessType = type)
    // 4. 设置科室
    const setDep = (id: string) => (consult.value.depId = id)
    // 5. 设置病情描述相关信息
    const setIllnessDesc = (desc: ConsultIllness) => {
      consult.value.illnessDesc = desc.illnessDesc
      consult.value.illnessTime = desc.illnessTime
      consult.value.consultFlag = desc.consultFlag
      consult.value.pictures = desc.pictures
    }
    // 6. 设置患者
    const setPatient = (patientId: string) =>
      (consult.value.patientId = patientId)

    // 7. 设置优惠券
    const setCoupon = (id: string) => (consult.value.couponId = id)

    // 8. 清空仓库
    const clear = () => (consult.value = {})

    return {
      consult,
      setType,
      setIllnessType,
      setDep,
      setIllnessDesc,
      setPatient,
      setCoupon,
      clear
    }
  },
  {
    persist: true
  }
)
